package org.example.ttl;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.DeliverCallback;

public class DeadQueueConsumer2Test {

    public static void main(String[] args) throws Exception {

        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("localhost");
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();

        String deadQueue = "dead-queue2";
        channel.queueDeclare(deadQueue, false, false, false, null);
        channel.queueBind(deadQueue, "dead_exchange4", "black");
        System.out.println(" 等待接收死信队列消息.....");
        DeliverCallback deliverCallback = (consumerTag, delivery) -> {
            String message = new String(delivery.getBody(), "UTF-8");
            System.out.println("Consumer02 接收死信队列的消息" + message + "来源交换机=" + delivery.getEnvelope().getExchange());
        };
        channel.basicConsume(deadQueue, true, deliverCallback, consumerTag -> {
        });


    }
}
